package com.bookSystem.dao.Impl;/*
 * @Author:lsx
 * @Date:2024/9/14--09--14--20:43
 *
 */

import com.bookSystem.dao.BaseDao;
import com.bookSystem.dao.BookDao;
import com.bookSystem.entity.Book;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl extends BaseDao implements BookDao {

    @Override
    public List<Book> selectAll() {
       String sql = "select * from book";
        ResultSet rs = null;
        List<Book> list = new ArrayList<Book>();
        rs = super.queryResultSet(sql, null);
        try {
            if (rs != null){
                while (rs.next()) {
                    int bookId = rs.getInt("bookId");
                    String name = rs.getString("bookName");
                    String type = rs.getString("bookType");
                    String author = rs.getString("author");
                    Book book = new Book(bookId, name, type, author);
                    list.add(book);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(super.conn, super.ps, rs);
        }
        return list;
    }
}
